/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.szitar.forum.server;

import hu.szitar.forum.common.ForumEngine;
import hu.szitar.forum.common.Task;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 *
 * @author tircsil
 */
public class ForumEngineImpl implements ForumEngine{

    @Override
    public <T> T executeTask(Task<T> t) throws RemoteException {
        System.out.println("hu de megy");
        return t.execute();
        //throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public static void main(String[] args) {
        initServer();
    }
    
    public static void initServer(){
        /*if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }*/
        try {
            String name = "Compute";
            ForumEngineImpl engine = new ForumEngineImpl();
            ForumEngine stub =
                (ForumEngine) UnicastRemoteObject.exportObject(engine, 0);
            Registry registry = LocateRegistry.getRegistry();//TODO ide jönne a port szám
            registry.rebind(name, stub);
            System.out.println("ComputeEngine bound");
        } catch (Exception e) {
            System.err.println("ComputeEngine exception:");
            e.printStackTrace();
        }
    }
    
}
